import { observable, action, autorun, toJS } from 'mobx';
import { WeaTableNew, WeaForm } from 'comsMobx';

const { TableStore } = WeaTableNew;
import { ListStore } from './listStore';
import { WeaTools } from 'ecCom';
import { message } from 'antd';
import * as Apis from '../apis/search';
import { WeaLocaleProvider } from 'ecCom';

const getLabel = WeaLocaleProvider.getLabel;
export class CrmSearchQueryStore extends ListStore {
	@observable title = '查询客户';
    @observable rightMenu =[];
    @observable baseParams={
      selectType: 'search',
    }
    @observable showModal = false;
    @observable customerIds = '';
    @observable assignCrmName = '' ; // 客户名称

    @observable verified = false;
    @observable hasRight = false; // 权限
    @observable inited = false; //

    @action
    getConditionInfo=(params = {}) => {
      const newParams = { ...this.baseParams, ...params };
      Apis.getSearchTitleInfo(newParams).then((data) => {
        if (!data.hasright && typeof (data.hasright) !== 'undefined') {
          this.hasRight = data.hasright;
          this.verified = true;
        } else {
          this.inited = true;
          this.hasRight = true;
          this.verified = true;
          this.title = data.datas.title;
          this.rightMenu = data.datas.rightMenus;
          this.initDatas(newParams);
        }
      });
    }

    initDatas=(params = {}) => {
      // this.form = new WeaForm();
      this.condition = [];
      Apis.getSearchCondition(params).then((data) => {
        this.condition = data.datas;
        this.form = new WeaForm();
        // 根据高级搜索条件初始化form
        this.form && this.form.initFormFields(data.datas);
      });
    }

	@action
    doSearch=(params = {}) => {
      this.loading = true;
      // 获取表单的参数值
      const searchParamsAd = this.form.getFormParams();
      const newParams = { ...toJS(this.baseParams), ...searchParamsAd, ...params };
      // console.log("newParams",newParams);
      Apis.getCrmCustomerList(newParams).then((data) => {
        this.tableStore.getDatas(data.sessionkey, params.current || 1);
        this.dataKey = data.sessionkey;
        this.baseParams = { ...this.baseParams, ...params };
        this.loading = false;
      });
    }

	onShowColumn=() => { // 显示定制列
	  this.tableStore.setColSetVisible(true);
	  this.tableStore.tableColSet(true);
	}

	clearStatus=() => {
	  this.baseParams = {
	    selectType: 'search',
	  };
	  this.showModal = false;
	  this.showSearchAd = false;
	  this.clearFormFields();
	}
}

